<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Home extends CI_Controller {
	
	public function __construct()
	{
		parent::__construct();
		$this->load->model('novedades_model');
		$this->load->model('cursosyeventos_model');
		$this->load->library('session');
		$this->load->library('tank_auth');
		$this->load->helper('url');
		$this->load->helper('form');
		$this->load->helper('date');		
		$this->load->helper('text');
		
		// prevent caching
		$this->output->set_header('Last-Modified:'.gmdate('D, d M Y H:i:s').'GMT');
		$this->output->set_header('Cache-Control: no-store, no-cache, must-revalidate');
		$this->output->set_header('Cache-Control: post-check=0, pre-check=0',false);
		$this->output->set_header('Pragma: no-cache');
		
		// if no session, redirect to login page
		if(!$this->tank_auth->is_logged_in())
		{
			redirect('admin/login', 'refresh');
		}
	}
	
	public function index()
	{
		$data['title'] = 'Administrador - Starscamp';
		$data['session'] = array('username'=>ucfirst($this->tank_auth->get_username()));
		$data['novedades'] = $this->novedades_model->get_featured();
		$data['eventos'] = $this->cursosyeventos_model->get();
		foreach($data['eventos'] as $row)
		{
			$row->event_date = $this->_format_date($row->event_date);
		}
		
		$this->load->view('admin/templates/header', $data);
		$this->load->view('admin/index', $data);
		$this->load->view('admin/templates/footer', $data);
	}
	
	private function _format_date($str)
	{		
		$day = mdate('%d', strtotime($str));
		
		$month = str_replace(
			array('12', '11', '10', '09', '08', '07', '06', '05', '04', '03', '02', '01'),
			array('dic', 'nov', 'oct', 'sep', 'ago', 'jul', 'jun', 'may', 'abr', 'mar', 'feb', 'ene'),
			mdate('%m', strtotime($str))
		);
		
		return array('d'=>$day, 'm'=>$month);
	}
}

/* End of file home.php */
/* Location: ./application/controllers/admin/home.php */